#include "RingQueue.hpp"
#include <string>
#include <iostream>
#include <pthread.h>
#include <ctime>
#include <unistd.h>

void *Productor(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        //sleep(1);
        int x = rand() % 10 + 1;
        rq->Push(x);
        std::cout << "Producter-> " << x << std::endl;
    }
}

void *Consumer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        sleep(1);
        int x;
        rq->Pop(&x);
        std::cout << "Consumer-> " << x << std::endl;
    }
}

int main()
{
    srand(time(0) ^ getpid());
    RingQueue<int> *rq = new RingQueue<int>(10);
    pthread_t p1, p2, c1, c2;
    pthread_create(&p1, nullptr, Productor, rq);
    pthread_create(&c1, nullptr, Consumer, rq);
    pthread_create(&p2, nullptr, Productor, rq);
    pthread_create(&c2, nullptr, Consumer, rq);

    pthread_join(p1, nullptr);
    pthread_join(c1, nullptr);
    pthread_join(p2, nullptr);
    pthread_join(c2, nullptr);
    return 0;
}